package com.yeebo.controller.sys;

import com.alibaba.fastjson.JSONObject;
import com.yeebo.common.BaseController;
import com.yeebo.interceptor.Access;
import com.yeebo.rpc.config.GlobalParamService;
import com.yeebo.utils.ResponseUtils;
import com.yeebo.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("globalParam")
public class GlobalParamController extends BaseController {

    @Resource
    private GlobalParamService globalParamService;

    @Access
    @PostMapping(value = "/loadGlobalParamList")
    @ResponseBody
    public Result loadGlobalParamList(@RequestBody JSONObject requestBody,
                                      HttpServletRequest request) {
        Integer pageNo = requestBody.getInteger("pageNo");
        Integer pageSize = requestBody.getInteger("pageSize");
        String filterParamDesc = requestBody.getString("filterParamDesc");
        return ResponseUtils.success(globalParamService.loadGlobalParamList(filterParamDesc, pageNo, pageSize));
    }

    @Access
    @PostMapping(value = "/addGlobalParam")
    @ResponseBody
    public Result addGlobalParam(@RequestBody JSONObject requestBody,
                                 HttpServletRequest request) {
        String paramName = requestBody.getString("paramName");
        String paramValue = requestBody.getString("paramValue");
        String paramDesc = requestBody.getString("paramDesc");
        globalParamService.addGlobalParam(paramName, paramValue, paramDesc);
        return ResponseUtils.success("添加成功");
    }

    @Access
    @PostMapping(value = "/updateGlobalParam")
    @ResponseBody
    public Result updateGlobalParam(@RequestBody JSONObject requestBody,
                                    HttpServletRequest request) {
        String paramName = requestBody.getString("paramName");
        String paramValue = requestBody.getString("paramValue");
        String paramDesc = requestBody.getString("paramDesc");
        globalParamService.updateGlobalParam(paramName, paramValue, paramDesc);
        return ResponseUtils.success("更新成功");
    }

}
